package javaDemo07;

public class QueenTest {
    public static void main(String[] args) {
        int[] arr = new int[8];
        put(arr, 0);

    }

    public static void put(int[] arr, int index) {
        if (index == 8) {
            for (int i = 0; i < arr.length; i++) {
                if (i == 7) {
                    System.out.println(arr[i]);
                } else {
                    System.out.print(arr[i] + ",");
                }
            }
        } else {
            for (int i = 0; i < arr.length; i++) {
                arr[index] = i;
                if (decide(arr, index)) {
                    put(arr, index + 1);
                }
            }
        }
    }
    public static boolean decide(int[] arr, int index) {
        boolean boo = true;
        for (int i = 0; i < index; i++) {
            if (arr[i] == arr[index] || Math.abs(arr[index] - arr[i]) == Math.abs(index - i)) {
                boo = false;
            }
        }
        return boo;
    }

}

